import 'package:baselib/util/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app/controller/SplashControl.dart';
import 'package:flutter_app/login/webviewpage.dart';
import 'package:flutter_app/util/colours.dart';
import 'package:get/get.dart';

class WxDialog extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new WxDialogState();
  }

}

class WxDialogState extends State<WxDialog> {

  final SpalshController control = SpalshController.to;


  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    control.getQrcode(context);
    control.iswxExpire.value=false;
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    control.cancelQrTimer();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(4),
            shape: BoxShape.rectangle),
        child:Column(
          children: [
            _buildBar(context),
            Text("微信扫码登录",style:TextStyle(color: Color(0xff2E2F33),fontSize: 18),),
            InkWell(
              onTap: (){
                if(control.iswxExpire.value){
                  control.getQrcode(context);
                }
              },
              child: Container(
                width: 300,
                height: 300,
                child: Obx(()=>control.iswxExpire.value?Image.asset(CommonUtils.getImgPath("refresh_wx.png")):Image(image: NetworkImage(control.qrcodeBean.value.path==null?"":control.qrcodeBean.value.path))),
              ),
            ),
            Obx(()=>Text(control.iswxExpire.value?"二维码已过期":"请使用微信扫描二维码登录",style:TextStyle(color: Colors.red,fontSize: 18),)),
            GestureDetector(
              onTap: (){
                Get.back();
                showDialog(context: context,barrierDismissible:false,
                    builder: (ctx)=>control.buildLoginDialog());
              },
              child: Text("其他方式登录",style:TextStyle(color: Color(0xff2E2F33),fontSize: 18),),
            ),
          ],
        )
    );
  }



  ///关闭按钮
  _buildBar(context) =>
      Container(
        height: 30,
        alignment: Alignment.centerRight,
        margin: EdgeInsets.only(right: 10, top: 5),
        child: InkWell(
          onTap: () => Navigator.pop(context),
          child: Icon(
            Icons.close,
            color: Color(0xffD8D8D8),
          ),
        ),
      );
}